import { MenuFoldOutlined } from '@ant-design/icons-vue';
import { h } from 'vue';
import type { RouteRecordRaw } from 'vue-router';

// 获取路由
export const getMenusByRoutes = (routeList: readonly RouteRecordRaw[] = [], menus: any[] = []) => {
	if (!routeList.length) return;
	for (const route of routeList) {
		if (!route?.meta?.hidden) {
			menus.push({
				key: route?.meta?.key,
				title: route?.meta?.title,
				label: route?.meta?.title,
				path: route.path,
				icon: () => h(MenuFoldOutlined),
				children: route?.children?.length && route?.meta?.expand ? getMenusByRoutes(route.children) : null,
			});
		}
	}
	return menus;
};
